# -*- coding: utf-8 -*-
"""
@Time ： 2023/4/8 12:55
@Auth ： 叶东宇
@File ：deleteNthNode.py
"""

from Chain.Chain import *

def deleteNthNode(chain, n):
    l = 0
    p = chain.head
    while p.next:
        l += 1
        p = p.next
    if l < n:
        return chain
    else:
        tmp_l = 0
        p = chain.head
        while tmp_l != (l-n):
            p = p.next
            tmp_l += 1
        if p.next is None:
            return chain
        else:
            p.next = p.next.next
            return chain



if __name__ == "__main__":
    lis = [1,2,3,4,5]
    chain = create_chain_head(lis)
    print(chain.traverse())
    chain_ = deleteNthNode(chain, n=0)
    print(chain_.traverse())

